import React from 'react';
import ProductList from '../components/ProductList';
import { connect } from 'dva';

const Products = ({dispatch, products,location,history})=>{
    console.log('location:');
    console.log(location);
    console.log(history);
    function handleDelete(id){
        //触发删除事件，参数为 id
        dispatch({
            type: 'products/delete',
            payload: id
        });
    }
    return (<div>
        <h2>List of Products</h2>{products.length}
        <ProductList onDelete={handleDelete} products={products} />
        </div>);
}
//redux 的 connect
export default connect(({products})=>({products}))(Products);